package org.example.threadpooltaskexecutor.demos.service;


import org.example.threadpooltaskexecutor.demos.web.BasicController;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class MyAsyncService {


    @Async("asyncExecutor") // 指定使用的线程池 Bean 名称
    public CompletableFuture<String> asyncTask(String param) {

        try {
            System.out.println("线程池执行任务-"+param);
            Thread.sleep(10000); // 模拟耗时操作
            System.out.println("线程池执行完了-"+param);

//            return CompletableFuture.completedFuture("任务完成: " + BasicController.aa.get());
            return CompletableFuture.completedFuture("任务完成: "+param  );
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return CompletableFuture.completedFuture(String.valueOf(e));
        }
    }
}